//@author A0101119Y
#ifndef GCALPARSER_H
#define GCALPARSER_H

#include <Poco/JSON/JSON.h>
#include <Poco/JSON/Parser.h>
#include <Poco/Dynamic/Var.h>
#include <Poco/Timezone.h>
#include <map>
#include <string>
#include <vector>
#include <regex>
#include <sstream>
#include "CommonObjects.h"

namespace Twentyfifth {
	class GCalParser {
	protected:
		static const std::string LABEL_RESPONSE_EVENTS;
		static const std::string LABEL_RESPONSE_CALENDARS;
		static const std::string LABEL_ITEMS_ID;
		static const std::string LABEL_ITEMS_DESCRIPTION;
		static const std::string LABEL_ITEMS_VENUE;
		static const std::string LABEL_ITEMS_START;
		static const std::string LABEL_ITEMS_END;
		static const std::string LABEL_ITEMS_DATE;
		static const std::string LABEL_ITEMS_DATETIME;
		static const std::string LABEL_ITEMS_TIMEZONE;
		static const std::string LABEL_ITEMS_LAST_UPDATED;
		static const std::string LABEL_ITEMS_STATUS;

		static const std::regex REGEX_DATETIME_GOOGLE;
		static const std::regex REGEX_DATE_GOOGLE;
		static const std::string VALUE_DATETIME_GOOGLE;
		static const std::string VALUE_DATE_GOOGLE;
		static const std::string VALUE_TIMESTAMP_DAY;
		static const std::string VALUE_TIMESTAMP_MONTH;
		static const std::string VALUE_TIMESTAMP_YEAR;
		static const std::string VALUE_TIMESTAMP_HOUR;
		static const std::string VALUE_TIMESTAMP_MINUTE;
		static const std::string VALUE_TIMESTAMP_SECOND;
		static const std::string VALUE_ITEMS_DELETED_TRUE;
		static const std::string VALUE_ITEMS_DELETED_FALSE;

		std::string VALUE_TIMEZONE;
	public:
		GCalParser();
		Task parseObjectToTask(Poco::JSON::Object::Ptr POCOObjectPointer);
		Task parseResponseToTask(std::string JSONResponse);
		
		Poco::JSON::Object parseTaskToObject(Task task);
		Poco::JSON::Object parseMapToObject(std::map<std::string, std::string> userMap);
		Poco::JSON::Array parseTasksToArray(std::vector<Task> taskVector);
		
		std::vector<Task> parseArrayToTasks(Poco::JSON::Array::Ptr POCOArrayPointer);
		std::vector<Task> parseResponseToTasks(std::string JSONResponse);
		std::vector<std::map<std::string, std::string>> parseJsonArrayToVector(std::string JSONArray);
		std::vector<std::map<std::string, std::string>> parseResponseToCalendars(std::string JSONResponse);
		std::map<std::string, std::string> parseJsonToMap(std::string JSONResponse);
		
		DateTime parseDtGoogleToTask(std::string DateRFC3339);
		std::string parseDtTaskToGoogle(DateTime DateTask, bool isDateOnly = false);
		DateTime parseDtLastUpdatedToLocal(std::string DateRFC3339);
		
		void setTimeZone(std::string timezone);
	};
}

#endif // !GCALPARSER_H
